/*!
	\file LitCoreComponents.h
	\brief CoreComponent declaration

	This file describe the CoreComponent class
*/

#pragma once
#ifndef __LIT__CORE__COMPONENT__INCLUDED__HH__
#define __LIT__CORE__COMPONENT__INCLUDED__HH__

#include "LitPrerequisites.h"
#include "LitCoreComponentTypes.h"
#include "LitEnumStr.h"

namespace Lit
{
	/*! 
		The CoreComponent class is used as a starting point for modularity.
		It defines a base component, which is to be inherited.
		it is a the base class upon which all managers are derived from in this Framework.
	*/
	class LIT_API CoreComponent
	{
	public:
		typedef CoreComponentType Type;	/*!< CoreComponentType */

	public:
		/*!
			Constructs the component
			@param[in]	type	The type of the component
		*/
		CoreComponent();
		virtual ~CoreComponent();

		virtual Type type() const = 0;	/*!< Returns the type of the component */

#ifdef LIT_OGRE_SUPPORT
		 /*! 
			Initialises the component with OGRE details 
			\internal Called by Root, but you have to call Lit::Root::initialise() !
			@param[in,out]	win	The OGRE's main RenderWindow
			@param[in,out]	cam	The OGRE's main Camera
			@param[in,out]	cam	The OGRE's main SceneManager
		*/
		virtual void initialise( const OgreDetails &details );
		 /*! 
			One frame has been renderered by OGRE, so reflect the changes
			\internal Called by Root, but you have to call Lit::Root::renderOneFrame() !
			@param[in]	dt The last rendered frame time
		*/
		virtual bool renderOneFrame( float dt );
#else
		virtual void initialise();
#endif
		
		 /*! 
			Shutdowns the component
		*/
		virtual void shutdown();
	};
	
	typedef RefPtr<CoreComponent> CoreComponentPtr;
	/*!
		A list of component types
	*/
	class LIT_API CoreComponentList
	{
	public:
		typedef CoreComponent::Type Type; /*!< Component type */
		typedef std::vector<CoreComponentPtr> vec_t; /*!< List type */
		typedef std::vector<CoreComponentPtr>::iterator itor_t; /*!< Iterator type */
		typedef std::vector<CoreComponentPtr>::const_iterator const_itor_t; /*!< Const iterator type */
	protected:
		vec_t mTypes; /*!< Vector of components types */

	public:
		CoreComponentList(); /*!< Base constructor */
		/*! 
			Constructor
			@param[in] type	Adds one type to the list
		*/
		CoreComponentList( CoreComponentPtr com );  
		/*!
			Vector constructor 
			@param[in] types	A list of types to add
		*/
		CoreComponentList( const vec_t &types );  
		CoreComponentList(const CoreComponentList& list); /*!< Copy constructor */
		~CoreComponentList();
		
		itor_t begin(){ return mTypes.begin(); } /*!< Returns an iterator to the beginning of this list \return An itor_t pointing to the beginning of the list*/
		itor_t end(){ return mTypes.end(); }  /*!< Returns an iterator to the end of this list \return An itor_t pointing to the end of the list */
		const_itor_t begin() const{ return mTypes.begin(); }/*!< Returns a const iterator to the beginning of this list \return A const_itor_t pointing to the beginning of the list*/
		const_itor_t end() const{ return mTypes.end(); }/*!< Returns a const iterator to the end of this list \return A const_itor_t pointing to the end of the list */

		void add( CoreComponentPtr comp ); /*!< Adds a type to this list @param[in] comp The type to register*/
		void remove( CoreComponent::Type comp ); /*!< Removes a type from this list @param[in] comp The type to remove */
		bool has( CoreComponent::Type component ) const; /*!< Is a type in this list ? @param[in] component A component type to check \return true if it exists, false otherwise*/
		bool operator[]( CoreComponent::Type component ) const; /* Is a type in this list ? @param[in] component A component type to check \return true if it exists, false otherwise*/
		CoreComponentList& operator << ( CoreComponentPtr type ); /* Adds a type in this list @param[in] type The type to be added */

		vec_t& types(); /*!< Returns the internal list \return The internal std list of types */
		const vec_t& types() const; /*!< Returns the internal list \return The internal const std list of types */

		void reset();  /*!< Clears thist list */
	};
};

#endif